<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <label class="el-form-item-label">id</label>
        <el-input v-model="query.id" clearable placeholder="id" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">状态（0完结 1未完结）</label>
        <el-input v-model="query.status" clearable placeholder="状态（0完结 1未完结）" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <date-range-picker
          v-model="query.itemId"
          start-placeholder="itemIdStart"
          end-placeholder="itemIdStart"
          class="date-item"
        />
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="id">
            <el-input v-model="form.id" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="任务名称" prop="name">
            <el-input v-model="form.name" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="项目id" prop="itemId">
            <el-input v-model="form.itemId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="所属公司" prop="corpId">
            未设置字典，请手动设置 Select
          </el-form-item>
          <el-form-item label="状态（0完结 1未完结）" prop="status">
            未设置字典，请手动设置 Select
          </el-form-item>
          <el-form-item label="任务开始日期" prop="startDate">
            <el-date-picker v-model="form.startDate" type="datetime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="任务实际开始日期">
            <el-date-picker v-model="form.actualStartTime" type="datetime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="任务结束日期" prop="endDate">
            <el-date-picker v-model="form.endDate" type="datetime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="任务开始时间具体到小时">
            <el-date-picker v-model="form.startTime" type="datetime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="任务结束时间具体到小时">
            <el-date-picker v-model="form.endTime" type="datetime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="工作时长" prop="workTime">
            <el-input v-model="form.workTime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="工作内容" prop="workContent">
            <el-input v-model="form.workContent" :rows="3" type="textarea" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="执行人" prop="taskUserId">
            未设置字典，请手动设置 Select
          </el-form-item>
          <el-form-item label="任务状态" prop="taskStatus">
            未设置字典，请手动设置 Select
          </el-form-item>
          <el-form-item label="备注">
            <el-input v-model="form.remark" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="id" label="id" />
        <el-table-column prop="name" label="任务名称" />
        <el-table-column prop="itemId" label="项目id" />
        <el-table-column prop="corpId" label="所属公司" />
        <el-table-column prop="status" label="状态（0完结 1未完结）" />
        <el-table-column prop="startDate" label="任务开始日期">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.startDate) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="actualStartTime" label="任务实际开始日期">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.actualStartTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="endDate" label="任务结束日期">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.endDate) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="startTime" label="任务开始时间具体到小时">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.startTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="endTime" label="任务结束时间具体到小时">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.endTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="workTime" label="工作时长" />
        <el-table-column prop="workContent" label="工作内容" />
        <el-table-column prop="taskUserId" label="执行人" />
        <el-table-column prop="taskStatus" label="任务状态" />
        <el-table-column prop="remark" label="备注" />
        <el-table-column v-permission="['admin','taskWork:edit','taskWork:del']" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudTaskWork from '@/api/taskWork'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'


const defaultForm = { id: null, name: null, itemId: null, corpId: null, status: null, startDate: null, actualStartTime: null, endDate: null, startTime: null, endTime: null, workTime: null, workContent: null, taskUserId: null, taskStatus: null, createTime: null, createBy: null, updateTime: null, updateBy: null, remark: null }
export default {
  name: 'TaskWork',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({ title: 'WorkingController', url: 'api/taskWork', sort: 'id,desc', crudMethod: { ...crudTaskWork }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'taskWork:add'],
        edit: ['admin', 'taskWork:edit'],
        del: ['admin', 'taskWork:del']
      },
      rules: {
        name: [
          { required: true, message: '任务名称不能为空', trigger: 'blur' }
        ],
        itemId: [
          { required: true, message: '项目id不能为空', trigger: 'blur' }
        ],
        corpId: [
          { required: true, message: '所属公司不能为空', trigger: 'blur' }
        ],
        status: [
          { required: true, message: '状态（0完结 1未完结）不能为空', trigger: 'blur' }
        ],
        startDate: [
          { required: true, message: '任务开始日期不能为空', trigger: 'blur' }
        ],
        endDate: [
          { required: true, message: '任务结束日期不能为空', trigger: 'blur' }
        ],
        workTime: [
          { required: true, message: '工作时长不能为空', trigger: 'blur' }
        ],
        workContent: [
          { required: true, message: '工作内容不能为空', trigger: 'blur' }
        ],
        taskUserId: [
          { required: true, message: '执行人不能为空', trigger: 'blur' }
        ],
        taskStatus: [
          { required: true, message: '任务状态不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'id', display_name: 'id' },
        { key: 'status', display_name: '状态（0完结 1未完结）' }
      ]
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped>

</style>
